//
//  LoadingAttestViewController.m
//  Globalstone
//
//  Created by 刘建峰 on 16/7/20.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "LoadingAttestViewController.h"
#import "UICustomActionSheet.h"
#import "STActionSheet.h"
#import "DZNPhotoEditorViewController.h"
#import "UIImagePickerController+Edit.h"
#import "ShootVideoViewController.h"
#import <MediaPlayer/MediaPlayer.h>
#import <AVFoundation/AVFoundation.h>
#import <AssetsLibrary/AssetsLibrary.h>
@interface LoadingAttestViewController ()
@property (weak, nonatomic) IBOutlet UIView *navView;
@property (weak, nonatomic) IBOutlet UIScrollView *scroView;
@property (weak, nonatomic) IBOutlet UIButton *commitButton;
@property (weak, nonatomic) IBOutlet UIButton *maskButton;
@property (weak, nonatomic) IBOutlet UIView *changeImageView;
@property(nonatomic,assign)NSInteger photoButtonTag;
@property(nonatomic,assign)NSInteger imageViewTag;
@property(nonatomic,strong)NSMutableDictionary * photoDic;
@property (weak, nonatomic) IBOutlet UILabel *address;
@property (weak, nonatomic) IBOutlet UILabel *goodsPrice;
@property (weak, nonatomic) IBOutlet UILabel *payStatus;
@property (weak, nonatomic) IBOutlet UILabel *customeName;
@property (weak, nonatomic) IBOutlet UILabel *orderNumber;
@property (weak, nonatomic) IBOutlet UILabel *goodsName;
@property (weak, nonatomic) IBOutlet UILabel *orderType;

@property (strong, nonatomic) NSString *videoUrlName;//视频服务器名称
@end

@implementation LoadingAttestViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _photoDic = [NSMutableDictionary dictionary];
    _videoUrlName = @"";
    [self initViewLayout];
    [self getAttestInfo];
    // Do any additional setup after loading the view.
}

- (void)initViewLayout{
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.navView];
    [self adaptiveViewLayout:self.scroView];
    [self adaptiveViewLayout:self.changeImageView];
    _scroView.contentSize = flexibleSize(CGSizeMake(0, 735), NO);
    _commitButton.layer.cornerRadius = 4*VerticalRatio();
}

- (IBAction)back:(id)sender {
    [self backBtn];
}

#pragma mark === 录制视频
- (IBAction)gotoShootVideoClick:(UIButton *)sender {
    UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"PersonalStoryboard" bundle:nil];
    ShootVideoViewController * page = [storyBoard instantiateViewControllerWithIdentifier:@"ShootVideo"];
    page.urlGetter = ^(NSURL *videoUrl){
//        NSLog(@"----%@",videoUrl);
//        MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:[NSURL fileURLWithPath:videoUrl]];
//        moviePlayer.shouldAutoplay = NO;
//        UIImage *thumbnail = [moviePlayer thumbnailImageAtTime:0.0 timeOption:MPMovieTimeOptionNearestKeyFrame];
    _videoImage.image = [self getVideoPreViewImage:videoUrl];
        
    
    
    NSData *data = [NSData dataWithContentsOfURL:videoUrl];

    [self imageUpload:data];
    UIButton * button = [self.view viewWithTag:207];
    button.hidden = YES;
    };
    [[Common getNavigation]pushViewController:page];
    
}
//获取视频缩略图
- (UIImage *)getVideoPreViewImage:(NSURL *)videoPath
{
    AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:videoPath options:nil];
    AVAssetImageGenerator *gen = [[AVAssetImageGenerator alloc] initWithAsset:asset];
    gen.appliesPreferredTrackTransform = YES;
    CMTime time = CMTimeMakeWithSeconds(0.0, 10);
    NSError *error = nil;
    CMTime actualTime;
    CGImageRef image = [gen copyCGImageAtTime:time actualTime:&actualTime error:&error];
//    if (error) {
//        NSLog(@"截取视频图片失败:%@",error.localizedDescription);
//    }
    UIImage *img = [[UIImage alloc] initWithCGImage:image];
    CGImageRelease(image);
    return img;
}


- (void)getAttestInfo{
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    [dic setObject:[Common getLoginInfo][Key_User_userId] forKey:@"museId"];
    [dic setObject:[Common getLoginInfo][Key_User_password] forKey:@"musePwd"];
    [dic setObject:[Common getLoginInfo][Key_User_onlineKey] forKey:@"museOnlineTag"];
    [dic setObject:_indentId forKey:@"orderId"];
    [dic setObject:[NSString stringWithFormat:@"%ld",_type] forKey:@"orderType"];
    NSString * lan = [InternationalControl userLanguage];
    if ([lan isEqualToString:@"en"]) {
        [dic setObject:@"2" forKey:@"language"];
    }else{
        [dic setObject:@"1" forKey:@"language"];
    }
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:GS_toCertificationContainer withHttpType:@"POST" withTag:GS_GS_toCertificationContainer];
}

#pragma mark === 提交
- (IBAction)commitHandel:(id)sender {
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    [dic setObject:[Common getLoginInfo][Key_User_userId] forKey:@"museId"];
    [dic setObject:[Common getLoginInfo][Key_User_password] forKey:@"musePwd"];
    [dic setObject:[Common getLoginInfo][Key_User_onlineKey] forKey:@"museOnlineTag"];
    [dic setObject:[NSString stringWithFormat:@"%ld",_type] forKey:@"orderType"];
    [dic setObject:_indentId forKey:@"orderId"];
    NSString * lan = [InternationalControl userLanguage];
    if ([lan isEqualToString:@"en"]) {
        [dic setObject:@"2" forKey:@"language"];
    }else{
        [dic setObject:@"1" forKey:@"language"];
    }
    
        NSString * images = @"";
        NSString * attachs = @"";
        for (int i = 0; i<_photoDic.allKeys.count; i++) {
            NSInteger key = [_photoDic.allKeys[i]integerValue];
            NSString * image =[NSString stringWithFormat:@"%@,", _photoDic[[NSString stringWithFormat:@"%d",key]]];
            if (key>=200&&key<=204) {
                images = [images stringByAppendingString:image];
            }else{
                attachs = [attachs stringByAppendingString:image];
            }
        }
        if (images.length>0) {
            images = [images substringToIndex:images.length-1];
        }else{
            [CWHUDTips showTips:@"请上传装货图片!"];
            return;
        }
        if (attachs.length>0) {
            attachs = [attachs substringToIndex:attachs.length-1];
        }else{
            [CWHUDTips showTips:@"请上传附件!"];
            return;
        }
    
    if (_videoUrlName.length==0) {
        [CWHUDTips showTips:@"请上传装货视频!"];
        return;
    }
    
        [dic setObject:images forKey:@"image"];
        [dic setObject:attachs forKey:@"attach"];
        [dic setObject:_videoUrlName forKey:@"video"];
   
        [dic setObject:[NSString stringWithFormat:@"%d",_type] forKey:@"orderType"];
    
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:GS_containerCertification withHttpType:@"POST" withTag:GS_GS_containerCertification];
   
}

#pragma mark == 选择图片
- (IBAction)changeHeadImage:(UIButton *)sender {
    _photoButtonTag = sender.tag;
    _changeImageView.hidden = NO;
    _maskButton.hidden = NO;
}

#pragma mark == 取消
- (IBAction)hidden:(id)sender {
    _changeImageView.hidden = YES;
    _maskButton.hidden = YES;
}

#pragma mark == 选择上传照片方式
- (IBAction)chosePhoto:(UIButton *)sender {
    
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
        UICustomActionSheet* actionSheet = [[UICustomActionSheet alloc] initWithTitle:@"" delegate:nil buttonTitles:@[@"",@""]];
        
        [actionSheet setButtonColors:@[[UIColor clearColor]]];
        [actionSheet setBackgroundColor:[UIColor clearColor]];
        
        [actionSheet setSubtitle:@""];
        [actionSheet setSubtitleColor:[UIColor clearColor]];
        
        [actionSheet showInView:self.view];
        
        UIImagePickerController *controller = [[UIImagePickerController alloc] init];
        __weak __typeof(self)weakSelf = self;
        [actionSheet hideAlert];
        if (sender.tag==100){
            controller.allowsEditing = YES;
            controller.sourceType = UIImagePickerControllerSourceTypeCamera;
            controller.cropMode = DZNPhotoEditorViewControllerCropModeSquare;
            
            controller.finalizationBlock = ^(UIImagePickerController *picker, NSDictionary *info) {
                
                UIImage *image = info[UIImagePickerControllerEditedImage];
                UIImageView * imageView = [self.view viewWithTag:_photoButtonTag -1];
                imageView.image = image;
                UIButton * photoButton = [self.view viewWithTag:_photoButtonTag];
                 [photoButton setTitle:@"" forState:UIControlStateNormal];
                
                _imageViewTag = _photoButtonTag - 1;
                [self imageUpload:1 :image];
                // Dismiss when the crop mode was disabled
                if (picker.cropMode == DZNPhotoEditorViewControllerCropModeNone) {
                    [weakSelf dismissViewControllerAnimated:NO completion:^{
                    }];
                }
            };
            
            controller.cancellationBlock = ^(UIImagePickerController *picker) {
                
                // Dismiss when the crop mode was disabled or if the navigation stack has only one child view controller.
                if (picker.cropMode == DZNPhotoEditorViewControllerCropModeNone || picker.viewControllers.count == 1) {
                    [weakSelf dismissViewControllerAnimated:NO completion:^{
                    }];
                }
                else {
                    picker.cropMode = DZNPhotoEditorViewControllerCropModeSquare;
                    [picker popViewControllerAnimated:YES];
                }
            };
            [self presentViewController:controller animated:NO completion:^{}];
        }else if (sender.tag==101){
            controller.allowsEditing = YES;
            controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            controller.cropMode = DZNPhotoEditorViewControllerCropModeSquare;
            
            controller.finalizationBlock = ^(UIImagePickerController *picker, NSDictionary *info) {
                
                UIImage *image = info[UIImagePickerControllerEditedImage];
                UIImageView * imageView = [self.view viewWithTag:_photoButtonTag -1];
                imageView.image = image;
                UIButton * photoButton = [self.view viewWithTag:_photoButtonTag];
                [photoButton setTitle:@"" forState:UIControlStateNormal];
                
                _imageViewTag = _photoButtonTag - 1;
                [self imageUpload:1 :image];
                // Dismiss when the crop mode was disabled
                if (picker.cropMode == DZNPhotoEditorViewControllerCropModeNone) {
                    [weakSelf dismissViewControllerAnimated:NO completion:^{
                    }];
                }
            };
            
            controller.cancellationBlock = ^(UIImagePickerController *picker) {
                
                // Dismiss when the crop mode was disabled or if the navigation stack has only one child view controller.
                if (picker.cropMode == DZNPhotoEditorViewControllerCropModeNone || picker.viewControllers.count == 1) {
                    [weakSelf dismissViewControllerAnimated:NO completion:^{
                    }];
                }
                else {
                    picker.cropMode = DZNPhotoEditorViewControllerCropModeSquare;
                    [picker popViewControllerAnimated:YES];
                }
            };
            [self presentViewController:controller animated:NO completion:^{}];
        }
        
        
        
        
    }else {
        UIActionSheet *ss=[[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"" destructiveButtonTitle:@"" otherButtonTitles:@"", nil];
        [ss showInView:self.view];
        UIImagePickerController *controller = [[UIImagePickerController alloc] init];
        __weak __typeof(self)weakSelf = self;
        [ss dismissWithClickedButtonIndex:0 animated:YES];
        if (sender.tag==100){
            controller.allowsEditing = YES;
            controller.sourceType = UIImagePickerControllerSourceTypeCamera;
            controller.cropMode = DZNPhotoEditorViewControllerCropModeSquare;
            
            controller.finalizationBlock = ^(UIImagePickerController *picker, NSDictionary *info) {
                
                UIImage *image = info[UIImagePickerControllerEditedImage];
                UIImageView * imageView = [self.view viewWithTag:_photoButtonTag -1];
                imageView.image = image;
                UIButton * photoButton = [self.view viewWithTag:_photoButtonTag];
                [photoButton setTitle:@"" forState:UIControlStateNormal];
                
                _imageViewTag = _photoButtonTag - 1;
                [self imageUpload:1 :image];                // Dismiss when the crop mode was disabled
                if (picker.cropMode == DZNPhotoEditorViewControllerCropModeNone) {
                    [weakSelf dismissViewControllerAnimated:NO completion:^{
                    }];
                }
            };
            
            controller.cancellationBlock = ^(UIImagePickerController *picker) {
                
                // Dismiss when the crop mode was disabled or if the navigation stack has only one child view controller.
                if (picker.cropMode == DZNPhotoEditorViewControllerCropModeNone || picker.viewControllers.count == 1) {
                    [weakSelf dismissViewControllerAnimated:NO completion:^{
                    }];
                }
                else {
                    picker.cropMode = DZNPhotoEditorViewControllerCropModeSquare;
                    [picker popViewControllerAnimated:YES];
                }
            };
            [self presentViewController:controller animated:NO completion:^{}];
        }else if (sender.tag==101){
            controller.allowsEditing = YES;
            controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            controller.cropMode = DZNPhotoEditorViewControllerCropModeSquare;
            
            controller.finalizationBlock = ^(UIImagePickerController *picker, NSDictionary *info) {
                
                UIImage *image = info[UIImagePickerControllerEditedImage];
                UIImageView * imageView = [self.view viewWithTag:_photoButtonTag -1];
                imageView.image = image;
                UIButton * photoButton = [self.view viewWithTag:_photoButtonTag];
                [photoButton setTitle:@"" forState:UIControlStateNormal];
                
                _imageViewTag = _photoButtonTag - 1;
                [self imageUpload:1 :image];
                // Dismiss when the crop mode was disabled
                if (picker.cropMode == DZNPhotoEditorViewControllerCropModeNone) {
                    [weakSelf dismissViewControllerAnimated:NO completion:^{
                    }];
                }
            };
            
            controller.cancellationBlock = ^(UIImagePickerController *picker) {
                
                // Dismiss when the crop mode was disabled or if the navigation stack has only one child view controller.
                if (picker.cropMode == DZNPhotoEditorViewControllerCropModeNone || picker.viewControllers.count == 1) {
                    [weakSelf dismissViewControllerAnimated:NO completion:^{
                    }];
                }
                else {
                    picker.cropMode = DZNPhotoEditorViewControllerCropModeSquare;
                    [picker popViewControllerAnimated:YES];
                }
            };
            [self presentViewController:controller animated:NO completion:^{}];
        }
        
    }
    
    _changeImageView.hidden = YES;
    _maskButton.hidden = YES;
}
#pragma mark - 上传视频--------------------------
- (void)imageUpload:(NSData *)data{
    NSString *url = [NSString stringWithFormat:@"%@",IP_Address_IMAGE];
    //分界线的标识符
    NSString *TWITTERFON_FORM_BOUNDARY = @"AaB03x";
    //根据url初始化request
    NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]
                                                           cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
                                                       timeoutInterval:10];
    //分界线 --AaB03x
    NSString *MPboundary=[[NSString alloc]initWithFormat:@"--%@",TWITTERFON_FORM_BOUNDARY];
    //结束符 AaB03x--
    NSString *endMPboundary=[[NSString alloc]initWithFormat:@"%@--",MPboundary];
    //要上传的图片
    //    UIImage *image=[params objectForKey:@"pic"];
    //http body的字符串
    NSMutableString *body=[[NSMutableString alloc]init];
    //设置HTTPHeader中Content-Type的值
    NSString* content=[[NSString alloc]initWithFormat:@"multipart/form-data; boundary=%@",TWITTERFON_FORM_BOUNDARY];
    ////添加分界线，换行
    [body appendFormat:@"%@\r\n",MPboundary];
    //声明pic字段，文件名为boris.png
    [body appendFormat:@"Content-Disposition: form-data; name=\"pic\"; filename=\"video.mp4\"\r\n"];
    //声明上传文件的格式
    [body appendFormat:@"Content-Type: image/png\r\n\r\n"];
    //    [body appendFormat:@"Content-Type: %@\r\n\r\n",content];
    //声明结束符：--AaB03x--
    NSString *end=[[NSString alloc]initWithFormat:@"\r\n%@",endMPboundary];
    //声明myRequestData，用来放入http body
    NSMutableData *myRequestData=[NSMutableData data];
    //将body字符串转化为UTF8格式的二进制
    [myRequestData appendData:[body dataUsingEncoding:NSUTF8StringEncoding]];
    //将image的data加入
    [myRequestData appendData:data];
    //加入结束符--AaB03x--
    [myRequestData appendData:[end dataUsingEncoding:NSUTF8StringEncoding]];
    NSString *headerUserAgent=@"";
    if ([Common getLoginStatus]) {
        NSString *userName = [[Common getLoginInfo] objectForKey:Key_User_nickname];
        NSString *userId  = [NSString stringWithFormat:@"%@",[[Common getLoginInfo] objectForKey:Key_User_userId]];
        NSString *encryptPwd  = [ [Common getLoginInfo] objectForKey:Key_User_password];
        NSString *localUserIdentify  = [[UIDevice currentDevice].identifierForVendor UUIDString];
        headerUserAgent = [NSString stringWithFormat:@"%@|%@|%@|%@",userName,userId,encryptPwd,localUserIdentify];
    }else{
        headerUserAgent = @"|||";
    }
    
    //设置HTTPHeader
    [request setValue:content forHTTPHeaderField:@"Content-Type"];
    //设置User-Agent
    [request setValue:headerUserAgent forHTTPHeaderField:@"User-Agent"];
    //设置Content-Length
    [request setValue:[NSString stringWithFormat:@"%d", [myRequestData length]] forHTTPHeaderField:@"Content-Length"];
    //设置http body
    [request setHTTPBody:myRequestData];
    //http method
    [request setHTTPMethod:@"POST"];
    
    //建立连接，设置代理
    //    NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
    //上传文件开始
    NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    //获得返回值
    NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
    
    NSData *jsonData = [returnString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *error = nil;
    NSMutableDictionary *dictionary = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error];
    
    //取得返回的图片名
    //    NSArray* array = [returnString componentsSeparatedByString:@"###"];
    //    NSString * image = [NSString stringWithFormat:@"%@", dictionary[@"result"][0][@"simaId"]];
    
    
    NSString * image = dictionary[@"title"];
    _videoUrlName = image;
//    [_photoDic setObject:image forKey:[NSString stringWithFormat:@"%d",_imageViewTag]];
}

#pragma mark - 上传图片--------------------------
- (void)imageUpload:(int)numberImg:(UIImage *)imageImage{
    NSString *url = [NSString stringWithFormat:@"%@",IP_Address_IMAGE];
    //分界线的标识符
    NSString *TWITTERFON_FORM_BOUNDARY = @"AaB03x";
    //根据url初始化request
    NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]
                                                           cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
                                                       timeoutInterval:10];
    //分界线 --AaB03x
    NSString *MPboundary=[[NSString alloc]initWithFormat:@"--%@",TWITTERFON_FORM_BOUNDARY];
    //结束符 AaB03x--
    NSString *endMPboundary=[[NSString alloc]initWithFormat:@"%@--",MPboundary];
    //要上传的图片
    //    UIImage *image=[params objectForKey:@"pic"];
    //得到图片的data
    CGSize newSize = CGSizeMake(80, 80);
    UIGraphicsBeginImageContext(newSize);
    [imageImage drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    NSData* data  = UIImageJPEGRepresentation(newImage, 0.7);
    //http body的字符串
    NSMutableString *body=[[NSMutableString alloc]init];
    //设置HTTPHeader中Content-Type的值
    NSString* content=[[NSString alloc]initWithFormat:@"multipart/form-data; boundary=%@",TWITTERFON_FORM_BOUNDARY];
    ////添加分界线，换行
    [body appendFormat:@"%@\r\n",MPboundary];
    //声明pic字段，文件名为boris.png
    [body appendFormat:@"Content-Disposition: form-data; name=\"pic\"; filename=\"boris.png\"\r\n"];
    //声明上传文件的格式
    [body appendFormat:@"Content-Type: image/png\r\n\r\n"];
    //    [body appendFormat:@"Content-Type: %@\r\n\r\n",content];
    //声明结束符：--AaB03x--
    NSString *end=[[NSString alloc]initWithFormat:@"\r\n%@",endMPboundary];
    //声明myRequestData，用来放入http body
    NSMutableData *myRequestData=[NSMutableData data];
    //将body字符串转化为UTF8格式的二进制
    [myRequestData appendData:[body dataUsingEncoding:NSUTF8StringEncoding]];
    //将image的data加入
    [myRequestData appendData:data];
    //加入结束符--AaB03x--
    [myRequestData appendData:[end dataUsingEncoding:NSUTF8StringEncoding]];
    NSString *headerUserAgent=@"";
    if ([Common getLoginStatus]) {
        NSString *userName = [[Common getLoginInfo] objectForKey:Key_User_nickname];
        NSString *userId  = [NSString stringWithFormat:@"%@",[[Common getLoginInfo] objectForKey:Key_User_userId]];
        NSString *encryptPwd  = [ [Common getLoginInfo] objectForKey:Key_User_password];
        NSString *localUserIdentify  = [[UIDevice currentDevice].identifierForVendor UUIDString];
        headerUserAgent = [NSString stringWithFormat:@"%@|%@|%@|%@",userName,userId,encryptPwd,localUserIdentify];
    }else{
        headerUserAgent = @"|||";
    }
    
    //设置HTTPHeader
    [request setValue:content forHTTPHeaderField:@"Content-Type"];
    //设置User-Agent
    [request setValue:headerUserAgent forHTTPHeaderField:@"User-Agent"];
    //设置Content-Length
    [request setValue:[NSString stringWithFormat:@"%d", [myRequestData length]] forHTTPHeaderField:@"Content-Length"];
    //设置http body
    [request setHTTPBody:myRequestData];
    //http method
    [request setHTTPMethod:@"POST"];
    
    //建立连接，设置代理
    //    NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
    //上传文件开始
    NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    //获得返回值
    NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
    
    NSData *jsonData = [returnString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *error = nil;
    NSMutableDictionary *dictionary = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error];
    
    //取得返回的图片名
    //    NSArray* array = [returnString componentsSeparatedByString:@"###"];
    //    NSString * image = [NSString stringWithFormat:@"%@", dictionary[@"result"][0][@"simaId"]];
    NSString * image = dictionary[@"title"];
    [_photoDic setObject:image forKey:[NSString stringWithFormat:@"%d",_imageViewTag]];
}

#pragma   mark---- GetADBanner Request Delegate

-(void)fetchDatabaseFinished:(NSMutableDictionary *)database withTag:(NSInteger)tag{
    
    if (tag==GS_GS_containerCertification) {
        
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else {
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            [self backBtn];
        }
    }else if (tag == GS_GS_toCertificationContainer){
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else {
            if (![database[@"result"][@"order"] isEqual:[NSNull null]]) {
                NSDictionary * dic= database[@"result"][@"order"];
                _orderNumber.text = [NSString stringWithFormat:@"%@",dic[@"orderSysId"]];
                _goodsName.text = [NSString stringWithFormat:@"%@",dic[@"orderTypeName"]];
                _address.text = [NSString stringWithFormat:@"%@",dic[@"orderAddress"]];
                _goodsPrice.text = [NSString stringWithFormat:@"￥%.2f",[dic[@"orderPrice"] floatValue]];
                NSString * type = [NSString stringWithFormat:@"%@",dic[@"orderType"]];
                if ([type isEqualToString:@"1"]) {
                    _orderType.text = @"出口";
                }else{
                    _orderType.text = @"进口";
                }
                
                _customeName.text = [NSString stringWithFormat:@"%@",database[@"result"][@"customer"][@"museTrueName"]];
                NSArray * array = @[@"未支付",@"支付定金",@"全额支付"];
                NSInteger payType = [database[@"result"][@"depositPayStatus"]integerValue];
                _payStatus.text = array[payType-1];
            }
           
        }
    }
}

-(void)fetchDatabaseFailed:(NSError *)error message:(NSString *)message{
    
    [self dismissWaitDialog];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
